package com.example.home.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.example.home.R;
import com.example.home.bean.CatRecordBean;

import java.util.List;

public class CatRecordAdapter extends RecyclerView.Adapter<CatRecordAdapter.Myholdy> {
    private Context context;
    private List<CatRecordBean.RowsBean> list;
    private boolean showDataAll = false; // 用于控制是否显示所有数据

    public void setShowAllData(boolean showAllData) {
        this.showDataAll = showAllData;
        notifyDataSetChanged(); // 刷新 RecyclerView 以显示所有数据
    }

    public CatRecordAdapter(Context context, List<CatRecordBean.RowsBean> list) {
        this.context = context;
        this.list = list;
    }


    @NonNull
    @Override
    public Myholdy onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_record, null);
        return new Myholdy(view);
    }

    @Override
    public void onBindViewHolder(@NonNull Myholdy holder, int position) {
        holder.Cat_id.setText("车牌号:" + list.get(position).getPlateNumber());
        holder.money.setText("收费金额:" + list.get(position).getMonetary()+"元");
        holder.go_time.setText("入场时间:" + list.get(position).getEntryTime());
        holder.back_time.setText("出场时间:" + list.get(position).getOutTime());
        holder.name.setText("停车场:" + list.get(position).getParkName());
    }

    @Override
    public int getItemCount() {
            return showDataAll ? list.size() : Math.min(list.size(), 5);
    }

    public class Myholdy extends RecyclerView.ViewHolder {
        TextView Cat_id;
        TextView money;
        TextView go_time;
        TextView back_time;
        TextView name;
        public Myholdy(@NonNull View itemView) {
            super(itemView);
            Cat_id = itemView.findViewById(R.id.Cat_id);
            money = itemView.findViewById(R.id.money);
            go_time = itemView.findViewById(R.id.go_time);
            back_time = itemView.findViewById(R.id.back_time);
            name = itemView.findViewById(R.id.name);
        }
    }
}
